<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>卷烟消费 -- 消费行为记录统计</title>
    <link rel="stylesheet" href="${contextPath}/static/statistics/css/bootstrap.min.css">
    <link rel="stylesheet" href="${contextPath}/static/statistics/css/bootstrap-datetimepicker.min.css">
    <link rel="stylesheet" href="${contextPath}/static/layer/css/layui.css">
    <link href="${contextPath}/static/ztree/css/zTreeStyle.css" rel="stylesheet" />
    <script src="${contextPath}/static/statistics/js/jquery.js"></script>
    <script src="${contextPath}/static/statistics/js/bootstrap.min.js"></script>
    <script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.min.js"></script>
    <script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.fr.js"></script>
    <script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="${contextPath}/static/statistics/js/bootstrap.min.js"></script>
    <script src="${contextPath}/static/statistics/js/vue.js"></script>
    <script src="${contextPath}/static/statistics/js/echarts.min.js"></script>
    <script type="text/javascript" src="${contextPath}/static/statistics/js/jquery.mockjax.js"></script>
    <script type="text/javascript" src="${contextPath}/static/statistics/js/jquery.autocomplete.js"></script>
    <script type="text/javascript" src="${contextPath}/static/ztree/js/jquery.ztree.core-3.5.js"></script>
    <script type="text/javascript" src="${contextPath}/static/ztree/js/jquery.ztree.excheck-3.5.js"></script>
    <script type="text/javascript" src="${contextPath}/static/util/my-autocomplete.js"></script>
    <style>
        .autocomplete-suggestions {
            border: 1px solid #999;
            background: #FFF;
            overflow: auto;
        }

        .autocomplete-suggestion {
            padding: 2px 5px;
            white-space: nowrap;
            overflow: hidden;
        }

        .autocomplete-selected {
            background: #F0F0F0;
        }

        .autocomplete-suggestions strong {
            font-weight: normal;
            color: #3399FF;
        }
    </style>
</head>
<body style="background: rgba(119, 118, 118, 0.15);">
<div class="container-fluid" id="app">
    <form class="form-inline" style="margin-top: 50px; margin-bottom: 5px;">
        <shiro:hasPermission name="CLOUDERPORDERSPLADMINORDER:STATISTICS">
            <div class="form-group">
                <input id="cityNameInput" onfocus="this.value=''" class="form-control input-sm" type="text" placeholder="市局名称">
            </div>
            <div class="form-group">
                <input id="quXianNameInput" onfocus="this.value=''" class="form-control input-sm" type="text"
                       placeholder="区县名称">
            </div>
        </shiro:hasPermission>
        <shiro:lacksPermission name="CLOUDERPORDERSPLEMPORDER:STATISTICS">
            <shiro:lacksPermission name="CLOUDERPORDERSPLCHANNELORDER:STATISTICS">
                <div class="form-group">
                    <input id="channelNameInput" onfocus="this.value=''" class="form-control input-sm" type="text"
                           placeholder="渠道名称">
                </div>
            </shiro:lacksPermission>
            <div class="form-group">
                <input id="empNameInput" onfocus="this.value=''" class="form-control input-sm" type="text"
                       placeholder="客户经理名称">
            </div>
        </shiro:lacksPermission>
        <div class="form-group input-group">
            <input id="prodNameInput" class="form-control input-sm" readonly  type="text" placeholder="未选择品规">
            <span class="input-group-btn">
				<button type="button" class="btn btn-default btn-sm" title="选择商品作为查询条件" onclick="javascript:$('#gridSystemModal').modal('show');">选择</button>
			</span>
        </div>
        <div class="form-group">
            <input id="beginOperatorTimeInput" class="form-control input-sm"   type="text" placeholder="请选择开始时间">
        </div>
        <div class="form-group">
            <input id="endOperatorTimeInput" class="form-control input-sm"   type="text" placeholder="请选择结束时间">
        </div>
        <div class="form-group">
            <input id="phoneInput" class="form-control input-sm" v-model="queryModel.stringMap.phone"  type="text" placeholder="电话号码">
        </div>

        <button type="button" class="btn btn-sm btn-success" @click="getOrder(1);">查询</button>
       <%-- <button type="button" title="根据查询条件导出所有记录" onclick="exportExcel();"
                class="btn btn-sm btn-info">导出Excel
        </button>--%>
    </form>
    <div class="row" style="background-color: rgb(53, 147, 202);margin-right: 0px;margin-left: 0px; height: 37px;">
        <div class="col-sm-10" style="margin-top: 6px;">
            <strong style="font-size: 18px;color: #f9f9f9;">卷烟消费行为记录统计</strong>
        </div>
        <div class="col-sm-2" style="text-align: right">

        </div>
    </div>
    <div class="table-responsive" id="tableContainer" style="height: 365px">
        <table class="table table-striped table-condensed table-bordered">
            <thead style="background-color:#eee;">
            <tr>
                <th>身份证</th>
                <th>消费ID</th>
                <th>电话</th>
                <th>性别</th>
                <th>年龄</th>
                <th>消费次数</th>
                <th>购买均价</th>
                <th>最后购买烟品</th>
                <th>最后购买地点</th>
                <th>最后购买时间</th>

            </tr>
            </thead>
            <tbody>

            <tr v-for="order in orderList">
                <td>{{order.IDENTITY_IDCARD}}</td>
                <%--<td>{{order.bankCar}}</td>--%>
                <td><a style="color: #0aa5df;" href="javascript:void(0)" @click="showMap(order.CUSTOMER_ID)">{{order.CUSTOMER_ID}}</a></td>
                <td>{{order.MOBILE}}</td>
                <td>{{order.IDENTITY_SEX == '-1' ? '未知': order.IDENTITY_SEX}}</td>
                <td>{{order.IDENTITY_AGE}}</td>
                <td>{{order.COUNT_ID}}</td>
                <td>{{order.AVG_PRICE}}</td>
                <td>{{order.PRODUCT_NAME}}</td>
                <td>{{order.ADDRESS}}</td>
                <td>{{order.OPERATOR_TIME_STR}}</td>
            </tr>
            </tbody>
        </table>
    </div>
    <div style="text-align: right;margin-top: 10px;" id="pageDiv"></div>

</div>
<form action="${contextPath}/checking/smokeCustomerListExportExcel" method="post" id="exportExcel" style="display:none">
    <input type="hidden" name="stringMap['productCode']"  id="exportExcelParamProductCode">
    <input type="hidden" name="stringMap['beginOperatorTime']" id="exportExcelParamBOperatorTime">
    <input type="hidden" name="stringMap['endOperatorTime']" id="exportExcelParamEOperatorTime">
    <input type="hidden" name="stringMap['phone']" id="exportExcelParamPhone">

    <input type="hidden" name="stringMap['cityName']" id="exportExcelCityName">
    <input type="hidden" name="stringMap['quXianName']" id="exportExcelQuXianName">
    <input type="hidden" name="stringMap['channelName']" id="exportExcelChannelName">
    <input type="hidden" name="stringMap['empName']" id="exportExcelEmpName">

    <input type="hidden" name="stringMap['tableType']" value="smokeCustomerList">
</form>


<div class="modal fade" tabindex="-1" role="dialog" id="gridSystemModal" aria-labelledby="gridSystemModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="gridSystemModalLabel">选择品规</h4>
            </div>
            <div class="modal-body">
                <div class="content_wrap">
                    <div class="zTreeDemoBackground left">
                        <ul id="treeDemo" class="ztree"></ul>
                    </div>

                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="selectProductTreeNames();">确认</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- 地图 -->
<div id="mapContainer" class="hide">
    <div style="width: 900px;height: 558px" id="userLocationMap"></div>
</div>
</body>
<script src=${contextPath}/static/layer/layui.all.js></script>
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=ec3688cc2547017ad39dd55153d18b85"></script>
<script type="text/javascript">
    var laypage = layui.laypage
        , layer = layui.layer;

    //地图相关

    var map = new AMap.Map('userLocationMap',{
       // resizeEnable: true,
        zoom: 12,
        //center: [116.39,39.9]//new AMap.LngLat(116.39,39.9)
    });

    AMap.plugin(['AMap.ToolBar', 'AMap.Scale', 'AMap.MapType'], function() {
        toolBar = new AMap.ToolBar();  //工具条
        scale = new AMap.Scale();    //比例尺
        map.addControl(toolBar);
        map.addControl(scale);
    });



    var app = new Vue({
        el: '#app',
        data: {
            orderList: [],
            queryModel: {
                stringMap: {
                    page: 1,
                    productCode:"",
                    beginOperatorTime:"",
                    endOperatorTime:"",
                    phone:"",
                    cityName : '',
                    quXianName : '',
                    channelName : '',
                    empName : ''
                },

            },
            markers : [],
        },
        methods: {
            getOrder: function (page) {
                layer.load(1)
                app.queryModel.stringMap.page = page;
                this.disposeQP();
                $.ajax({
                    url: '${contextPath}/checking/getSmokeCustomerStatisticsListByPageQuery',
                    type: 'post',
                    data: app.queryModel,
                    success: function (data) {
                        layer.closeAll('loading')
                        if (data.success == false) {
                            layer.msg("获取出错：" + data.message)
                            return
                        }
                        //console.log(data)
                        var dataArray = data.recordList;
                        if (dataArray.length == 0) {
                            layer.msg("查询没有数据")
                        }
                        app.orderList = dataArray
                        laypage({
                            cont: 'pageDiv'
                            , pages: data.pageCount //总页数
                            , groups: 5 //连续显示分页数
                            , curr: data.currentPage
                            , skin: '#1E9FFF',
                            jump: function (obj, first) {
                                var curr = obj.curr;
                                if (!first) {
                                    app.getOrder(curr)
                                }
                            }
                        });
                    },
                    error: function (error) {
                        layer.closeAll('loading');
                        layer.msg('网络错误');
                        //console.log(error)
                    }
                })
            },
            disposeQP : function () {
                var cityName = $("#cityNameInput").val();
                var quXianName = $("#quXianNameInput").val();
                var channelName = $("#channelNameInput").val();
                var empName = $("#empNameInput").val();

                this.queryModel.stringMap.cityName = cityName;
                this.queryModel.stringMap.quXianName = quXianName;
                this.queryModel.stringMap.channelName = channelName;
                this.queryModel.stringMap.empName = empName;
            },
            showMap : function (phone) {
                //查询店铺信息
                layer.load(1)
                $.ajax({
                    url: '${contextPath}/checking/getBuyShopInfoByPhone',
                    type: 'post',
                    data: {
                        phone:phone,
                    },
                    success: function (data) {
                        layer.closeAll('loading')
                        if (data.success == false) {
                            layer.msg("获取出错：" + data.message)
                            return
                        }
                        //console.log(data)
                        var markerInfos = data.data
                        if (markerInfos.length==0) {
                            layer.msg("店铺信息异常");
                            return
                        }
                        map.setCenter(new AMap.LngLat(markerInfos[0].LONGITUDE,markerInfos[0].LATITUDE));
                        var markerList=[];
                        for (var index in markerInfos) {
                            var markeInfo = markerInfos[index];
                            var icon = null;

                            if (markeInfo.IMAGE && false) {
                                icon = new AMap.Icon({
                                    image : 'http://clouderp.skystorechain.com:20081/'+markeInfo.IMAGE,//24px*24px
                                    //icon可缺省，缺省时为默认的蓝色水滴图标，
                                    size : new AMap.Size(80,80)
                                });
                            }

                            var marker = new AMap.Marker({
                                icon : icon,//24px*24px
                                position : [markeInfo.LONGITUDE,markeInfo.LATITUDE],
                                title:'在'+markeInfo.SHOP_NAME+'购买过'+markeInfo.BUYTIME+'次',
                                offset : new AMap.Pixel(-12,-12),
                                map : map
                            });

                            //鼠标点击marker弹出自定义的信息窗体
                            AMap.event.addListener(marker, 'click', function() {

                                var infoWindow = new AMap.InfoWindow({
                                    content:'在'+markeInfo.SHOP_NAME+'购买过'+markeInfo.BUYTIME+'次'  //使用默认信息窗体框样式，显示信息内容
                                });
                                infoWindow.open(map, marker.getPosition());
                            });



                            markerList.push(marker);

                        }
                        var $map = $("#mapContainer");
                        $map.removeClass('hide');
                        layer.open({
                            type: 1,
                            title: '购买地点分布',
                            closeBtn: 1,
                            area: ['900px', '600px'],
                            skin: 'yourclass',
                            content: $map,
                            end: function () {
                                $map.addClass("hide");
                                for (var indx in markerList) {
                                    markerList[index].setMap();
                                }
                                map.clearInfoWindow();
                            }
                        });
                    },
                    error: function (error) {
                        layer.closeAll('loading')
                        layer.msg('网络错误');
                        //console.log(error)
                    }
                })


            },
        }
    })

    app.getOrder(1)


    $('#beginOperatorTimeInput').datetimepicker({
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        minView: 2,
        showMeridian: 1,
        format: "yyyy-mm-dd",
        //startDate:new Date(),
    });

    $('#endOperatorTimeInput').datetimepicker({
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        minView: 2,
        showMeridian: 1,
        format: "yyyy-mm-dd",
        //startDate:new Date(),
    });

    $("#beginOperatorTimeInput").on("change",function () {
        app.queryModel.stringMap.beginOperatorTime = this.value
    });

    $("#endOperatorTimeInput").on("change",function () {
        app.queryModel.stringMap.endOperatorTime = this.value
    });
    var exportExcel = function () {
        if (!app.queryModel.stringMap.productCode && !app.queryModel.stringMap.beginOperatorTime && !app.queryModel.stringMap.endOperatorTime && !app.queryModel.stringMap.phone ) {
            //layer.msg("请选择导出条件");
            //return;
        }
        $("#exportExcelParamProductCode").val(app.queryModel.stringMap.productCode);
        $("#exportExcelParamBOperatorTime").val(app.queryModel.stringMap.beginOperatorTime);
        $("#exportExcelParamEOperatorTime").val(app.queryModel.stringMap.endOperatorTime);
        $("#exportExcelParamPhone").val(app.queryModel.stringMap.phone);

        $("#exportExcelCityName").val(app.queryModel.stringMap.cityName);
        $("#exportExcelQuXianName").val(app.queryModel.stringMap.quXianName);
        $("#exportExcelChannelName").val(app.queryModel.stringMap.channelName);
        $("#exportExcelEmpName").val(app.queryModel.stringMap.empName);

        $("#exportExcel").submit();
    }


    $.ajax({
        url : '${contextPath}/page/getProductThreeName',
        success : function (data) {
            if(data.success){
                var zNodes = data.data;

                var setting = {
                    check: {
                        enable: true,
                        chkStyle: "checkbox",
                    },

                    data: {
                        simpleData: {
                            enable: true ,
                            idKey: "ID",
                            pIdKey: "PID",
                            rootPId: '0',
                        },
                        key: {
                            name: "NAME"
                        },
                    },
                };

                $.fn.zTree.init($("#treeDemo"), setting, zNodes);
            }
        }
    })

    var selectProductTreeNames = function () {
        $("#gridSystemModal").modal('hide')
        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        var nodes =  zTree.getCheckedNodes();
        app.queryModel.stringMap.productCode = ""
        if (nodes.length == 0) {
            $("#prodNameInput").val("")
            return
        }
        var length = 0;
        for (var index in nodes) {
            var node = nodes[index]
            if (node.ISPRODNAME) {
                app.queryModel.stringMap.productCode = "'"+node.ID+"',"+app.queryModel.stringMap.productCode
                length++;
            }
        }
        app.queryModel.stringMap.productCode = app.queryModel.stringMap.productCode.substr(0,app.queryModel.stringMap.productCode.length-1)
        $("#prodNameInput").val("已选择"+length+"条品规")
    }


    var cityNode = null, quXianNode  = null, channelNode  = null, empNode  = null, custNode  = null, shopNode = null;

    <shiro:lacksPermission name="CLOUDERPORDERSPLEMPORDER:STATISTICS">
    empNode = '#empNameInput';
    channelNode = '#channelNameInput';
    <shiro:hasPermission name="CLOUDERPORDERSPLADMINORDER:STATISTICS">
    cityNode = '#cityNameInput';
    quXianNode = '#quXianNameInput';
    </shiro:hasPermission>
    </shiro:lacksPermission>

    organization_tree('${contextPath}',cityNode, quXianNode, channelNode, empNode, custNode, shopNode);
</script>
</html>





